If exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DeleteNotificationDocument]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[DeleteNotificationDocument]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/************************************************************************************************
* Name:		DeleteNotificationDocument                                                            
* Purpose:	Stored procedure for deleting the document 

* PARAMETERS  
*	Name			Description
* -------------------------	-----------------------------
* @protocolNumber 		protocolNumber
* @protocolProcessId 		Protocol ProcessId
* @boardId 			boardId
* @boardStatus			boardStatus
* @documentId 			documentId
************************************************************************************************/

CREATE PROCEDURE [dbo].[DeleteNotificationDocument]
(
 @protocolNumber varchar(12),
 @protocolProcessId int,
 @boardId int,
 @boardStatus varchar(50),
 @documentId int 
)
AS BEGIN
	Declare @boardStatusId int 
		Set @boardStatusId =  (Select Id from ProtocolBoardReviewStatusType where Name = @boardStatus)

	Delete from ProtocolDetails_Document_Map 
							where ProtocolNumber = @protocolNumber
								  and isnull(ProtocolProcessId,0) = @protocolProcessId 
								  and BoardId = @boardId 
						          and BoardStatusId = @boardStatusId
								  and DocumentId = @documentId
	
END
